#include <jni.h>
#include <string>

#include "cn_study_aviplayer_AbstractPlayerActivity.h"
#include "Common.h"
#include <android/bitmap.h>

extern "C" {
#include "avilib/avilib.h"
}

extern "C" JNIEXPORT jstring JNICALL
Java_cn_study_aviplayer_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

extern "C"
JNIEXPORT jlong JNICALL
Java_cn_study_aviplayer_AbstractPlayerActivity_open(JNIEnv *env, jclass clazz, jstring file_name) {

    avi_t *avi = 0;
    //获取文件名字并转换成字符串变量
    const char *cFileName = env->GetStringUTFChars(file_name, 0);
    if (0 == cFileName) {

        goto exit;
    }
    avi = AVI_open_input_file(cFileName, 1);
    env->ReleaseStringUTFChars(file_name, cFileName);

    if (0 == avi) {

        ThrowException(env, "java/io/IOException", AVI_strerror());
    }

    exit:
    return (jlong) avi;
}

extern "C"
JNIEXPORT jint JNICALL
Java_cn_study_aviplayer_AbstractPlayerActivity_getWidth(JNIEnv *env, jclass clazz, jlong avi) {

    return AVI_video_width((avi_t *) avi);
}

extern "C"
JNIEXPORT jint JNICALL
Java_cn_study_aviplayer_AbstractPlayerActivity_getHeight(JNIEnv *env, jclass clazz, jlong avi) {

    return AVI_video_height((avi_t *) avi);
}

extern "C"
JNIEXPORT jdouble JNICALL
Java_cn_study_aviplayer_AbstractPlayerActivity_getFrameRate(JNIEnv *env, jclass clazz, jlong avi) {

    return AVI_frame_rate((avi_t *) avi);
}

extern "C"
JNIEXPORT void JNICALL
Java_cn_study_aviplayer_AbstractPlayerActivity_close(JNIEnv *env, jclass clazz, jlong avi) {

    AVI_close((avi_t *) avi);
}



